package com.example.xss.lixinger.controller;

import cn.hutool.core.collection.CollUtil;
import com.example.xss.client.LixingerClient;
import com.example.xss.commom.enums.MetricNameEnum;
import com.example.xss.lixinger.model.CashFlowRes;
import com.example.xss.lixinger.model.IndexAnalysisRes;
import com.example.xss.lixinger.model.IndexAnalysisSource;
import com.example.xss.lixinger.model.Stock;
import com.example.xss.lixinger.service.LixingerFormService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * 控制页面跳转
 */
@Controller
@RequestMapping
@Slf4j
public class IndexController {

    @GetMapping
    public String index(ModelMap map) {
        return "index.html";
    }

    @GetMapping(value = "stock")
    public String stock(ModelMap map, @RequestParam("id") Long id
            , @RequestParam("stockCode") String stockCode) {
        log.info("id:{},code:{}", id,stockCode);
        Stock stock = LixingerClient.searchOne(stockCode);
        map.addAttribute("stock", stock);
        List<IndexAnalysisSource> sourceList = LixingerFormService.getSourceOfYear(5, id);
        List<IndexAnalysisRes> indexAnalysisList = LixingerFormService.indexAnalysis(sourceList);
        CashFlowRes xjl = LixingerFormService.xjl(sourceList);
        map.addAttribute("sourceList", sourceList);
        map.addAttribute("indexAnalysisList", indexAnalysisList);
        map.addAttribute("xjl", xjl);
        return "table.html";
    }
}
